package com.bcxk.order.controller;

import com.bcxk.common.Respond;
import com.bcxk.order.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;

/**
 * @author NieMingkun
 */
@RestController
@RequestMapping("redis")
public class RedisController {
    @Autowired
    RedisService redisService;
    @RequestMapping("test")
    public Respond test(@RequestParam("text") String orderNo){

        redisService.set(orderNo,orderNo,30L);
        return Respond.ok();
    }

    @RequestMapping("test1")
    public Respond test1(@RequestParam("text") String orderNo){
        System.out.println(redisService.getAll());
        LinkedHashSet set= (LinkedHashSet) redisService.getAll();
        ArrayList<String> list = new ArrayList<>(set);
        StringBuffer stringBuffer =new StringBuffer();
        Iterator iterator =list.iterator();
        while(iterator.hasNext()){
                stringBuffer.append(iterator.next()+",");
        }
        stringBuffer.append(0);
        System.out.println(stringBuffer);
        return Respond.ok(stringBuffer);
    }

}
